﻿@model MatchEventSummaryViewModel

@{ ViewBag.Title = "Events"; }

<div class="grid_2">
    @Html.LabelFor(m => m.MatchSummaryViewModel.MatchDate)
</div>
<div class="grid_10 clearfix">    
    @Html.Label(Model.MatchSummaryViewModel.MatchDate)
</div>

<div class="grid_2">
    @Html.LabelFor(m => m.MatchSummaryViewModel.CompetitionName)
</div>
<div class="grid_10 clearfix">    
    @Html.Label(Model.MatchSummaryViewModel.CompetitionName)
</div>

<div class="grid_2">
    @Html.LabelFor(m => m.MatchSummaryViewModel.VenueName)
</div>
<div class="grid_10 clearfix">    
    @Html.Label(Model.MatchSummaryViewModel.VenueName)
</div>

<div class="grid_5" style="text-align:right">    
    @Html.Label(Model.MatchSummaryViewModel.Team1Name)
</div>

<div class="grid_2" style="text-align:center">    
    @Html.Label(Model.MatchSummaryViewModel.FullTimeScore)
</div>

<div class="grid_5 clearfix">    
    @Html.Label(Model.MatchSummaryViewModel.Team2Name)
</div>

<div class="grid_12 clearfix" style="text-align:center">
    <h3>Select match events.</h3>
</div>

@using (Html.BeginForm(FormMethod.Post)) 
{
    @Html.AntiForgeryToken()
    @Html.HiddenFor(m => m.MatchGuid)

    <div class="grid_6">

        <div>@Model.MatchSummaryViewModel.Team1Name events</div>

        <div>
            @for (int i = 0; i < Model.MatchEvent1DataModels.ToArray().Count(); i++)
            {
                @Html.HiddenFor(m => m.MatchEvent1DataModels[i].MatchEventGuid)
                @Html.HiddenFor(m => m.MatchEvent1DataModels[i].ApprovalGuid)
                @Html.HiddenFor(m => m.MatchEvent1DataModels[i].MatchGuid)
                @Html.HiddenFor(m => m.MatchEvent1DataModels[i].TeamGuid)

                <div>
                    @(Html.Kendo().DropDownListFor(m => m.MatchEvent1DataModels[i].MatchEventType)
                        .DataValueField("Code")
                        .DataTextField("Description") 
                        .Value(((int)Model.MatchEvent1DataModels[i].MatchEventType).ToString())
                        .HtmlAttributes(new { style = "width: 100px" })
                        .BindTo(EnumCodePicker.Of<MatchEventType>())
                    )

                    @(Html.Kendo().ComboBoxFor(m => m.MatchEvent1DataModels[i].PersonGuid)
                        .DataValueField("Code")
                        .DataTextField("Description") 
                        .MinLength(2)
                        .Filter(FilterType.Contains)
                        .Delay(150)
                        .Placeholder("[Select player]")
                        .HighlightFirst(true)
                        .IgnoreCase(true)
                        .Suggest(true)
                        .HtmlAttributes(new { style = "width: 200px" })
                        .DataSource(source => { source.Read(read => { read.Action("GetPeopleJSON", "Edit"); }).ServerFiltering(true); })
                    )

                     @(Html.Kendo().NumericTextBoxFor(m => m.MatchEvent1DataModels[i].Minute)
                        .Decimals(0)
                        .Format("#")
                        .Min(0)
                        .Placeholder("[Mins]")
                        .HtmlAttributes(new { style = "width: 60px" })
                    )

                    <span>+</span>

                    @(Html.Kendo().NumericTextBoxFor(m => m.MatchEvent1DataModels[i].Extra)
                        .Decimals(0)
                        .Format("#")
                        .Min(0)
                        .Placeholder("[Extra]")
                        .HtmlAttributes(new { style = "width: 60px" })
                    )
                </div>
            }
        </div>

    </div>
    
    <div class="grid_6 clearfix">

        <div>@Model.MatchSummaryViewModel.Team2Name events</div>

        <div>
            @for (int i = 0; i < Model.MatchEvent2DataModels.ToArray().Count(); i++)
            {
                @Html.HiddenFor(m => m.MatchEvent2DataModels[i].MatchEventGuid)
                @Html.HiddenFor(m => m.MatchEvent2DataModels[i].ApprovalGuid)
                @Html.HiddenFor(m => m.MatchEvent2DataModels[i].MatchGuid)
                @Html.HiddenFor(m => m.MatchEvent2DataModels[i].TeamGuid)

                <div>
                    @(Html.Kendo().DropDownListFor(m => m.MatchEvent2DataModels[i].MatchEventType)
                        .DataValueField("Code")
                        .DataTextField("Description") 
                        .Value(((int)Model.MatchEvent2DataModels[i].MatchEventType).ToString())
                        .HtmlAttributes(new { style = "width: 100px" })
                        .BindTo(EnumCodePicker.Of<MatchEventType>())
                    )

                    @(Html.Kendo().ComboBoxFor(m => m.MatchEvent2DataModels[i].PersonGuid)
                        .DataValueField("Code")
                        .DataTextField("Description") 
                        .MinLength(2)
                        .Filter(FilterType.Contains)
                        .Delay(150)
                        .Placeholder("[Select player]")
                        .HighlightFirst(true)
                        .IgnoreCase(true)
                        .Suggest(true)
                        .HtmlAttributes(new { style = "width: 200px" })
                        .DataSource(source => { source.Read(read => { read.Action("GetPeopleJSON", "Edit"); }).ServerFiltering(true); })
                    )

                     @(Html.Kendo().NumericTextBoxFor(m => m.MatchEvent2DataModels[i].Minute)
                        .Decimals(0)
                        .Format("#")
                        .Min(0)
                        .Placeholder("[Mins]")
                        .HtmlAttributes(new { style = "width: 60px" })
                    )

                    <span>+</span>

                    @(Html.Kendo().NumericTextBoxFor(m => m.MatchEvent2DataModels[i].Extra)
                        .Decimals(0)
                        .Format("#")
                        .Min(0)
                        .Placeholder("[Extra]")
                        .HtmlAttributes(new { style = "width: 60px" })
                    )
                </div>
            }
        </div>
    </div>
    
    <div class="grid_12 clearfix">&nbsp;</div>
    
    <div class="grid_6">

        @Html.HiddenFor(m => m.NewTeam1MatchEvent.MatchGuid)
        @Html.HiddenFor(m => m.NewTeam1MatchEvent.TeamGuid)

        <div>New @Model.MatchSummaryViewModel.Team1Name event</div>

        <div>
            @(Html.Kendo().DropDownListFor(m => m.NewTeam1MatchEvent.MatchEventType)
                .DataValueField("Code")
                .DataTextField("Description") 
                .HtmlAttributes(new { style = "width: 100px" })
                .BindTo(EnumCodePicker.Of<MatchEventType>())
            )
            
            @(Html.Kendo().ComboBoxFor(m => m.NewTeam1MatchEvent.PersonGuid)
                .DataValueField("Code")
                .DataTextField("Description") 
                .MinLength(2)
                .Filter(FilterType.Contains)
                .Delay(150)
                .Placeholder("[Select player]")
                .HighlightFirst(true)
                .IgnoreCase(true)
                .Suggest(true)
                .Value(string.Empty)
                .HtmlAttributes(new { style = "width: 200px" })
                .DataSource(source => { source.Read(read => { read.Action("GetPeopleJSON", "Edit"); }).ServerFiltering(true); })
            )
            
            @(Html.Kendo().NumericTextBoxFor(m => m.NewTeam1MatchEvent.Minute)
                .Decimals(0)
                .Format("#")
                .Min(0)
                .Placeholder("[Mins]")
                .HtmlAttributes(new { style = "width: 60px" })
            )

            <span>+</span>

            @(Html.Kendo().NumericTextBoxFor(m => m.NewTeam1MatchEvent.Extra)
                .Decimals(0)
                .Format("#")
                .Min(0)
                .Placeholder("[Extra]")
                .HtmlAttributes(new { style = "width: 60px" })
            )
        </div>
    </div>
    
    <div class="grid_6 clearfix">

        @Html.HiddenFor(m => m.NewTeam2MatchEvent.MatchGuid)
        @Html.HiddenFor(m => m.NewTeam2MatchEvent.TeamGuid)

        <div>New @Model.MatchSummaryViewModel.Team2Name event</div>

        <div>
            @(Html.Kendo().DropDownListFor(m => m.NewTeam2MatchEvent.MatchEventType)
                .DataValueField("Code")
                .DataTextField("Description") 
                .HtmlAttributes(new { style = "width: 100px" })
                .BindTo(EnumCodePicker.Of<MatchEventType>())
            )

            @(Html.Kendo().ComboBoxFor(m => m.NewTeam2MatchEvent.PersonGuid)
                .DataValueField("Code")
                .DataTextField("Description") 
                .MinLength(2)
                .Filter(FilterType.Contains)
                .Delay(150)
                .Placeholder("[Select player]")
                .HighlightFirst(true)
                .IgnoreCase(true)
                .Suggest(true)
                .Value(string.Empty)
                .HtmlAttributes(new { style = "width: 200px" })
                .DataSource(source => { source.Read(read => { read.Action("GetPeopleJSON", "Edit"); }).ServerFiltering(true); })
            )
            
            @(Html.Kendo().NumericTextBoxFor(m => m.NewTeam2MatchEvent.Minute)
                .Decimals(0)
                .Format("#")
                .Min(0)
                .Placeholder("[Mins]")
                .HtmlAttributes(new { style = "width: 60px" })
            )

            <span>+</span>

            @(Html.Kendo().NumericTextBoxFor(m => m.NewTeam2MatchEvent.Extra)
                .Decimals(0)
                .Format("#")
                .Min(0)
                .Placeholder("[Extra]")
                .HtmlAttributes(new { style = "width: 60px" })
            )
        </div>

    </div>

    <div class="grid_12 clearfix" style="text-align:center">
        <br />
        <button class="k-button" type="submit" id="submitButton">
            <span class="k-icon k-i-tick"></span>
            <span>Save</span>
        </button>
    </div>
    
    <div class="grid_12 clearfix" style="text-align:right;">
        @Html.ActionLink("Search matches", "Index", "Search")
    </div>
    
}